package com.tecode.service.song;

import com.tecode.bean.Music;
import com.tecode.bean.Musicrejection;
import com.tecode.mapper.MusicMapper;
import com.tecode.mapper.MusicrejectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class SongServiceImp implements SongService{
    @Autowired
    private MusicMapper mapper;
    @Autowired
    private MusicrejectionMapper rejectMapper;
    @Override
    public List<Map> getList() {
        return mapper.getList();
    }

    @Override
    public Integer countMusics() {
        return mapper.countMusics();
    }

    @Override
    public List<Object> getAuditList(int cid) {
        return mapper.getAuditList(cid);
    }

    @Override
    public Integer countAudit(int cid) {
        return mapper.countAudit(cid);
    }

    @Override
    @Transactional
    public Integer audit(int musicId, int cid,int auditorId) {
        if (mapper.getRejectMusicById(musicId)!=null){
            mapper.delRejectMusicById(musicId);
        }
        return mapper.audit(musicId,cid,new Date(),auditorId);
    }

    @Override
    @Transactional
    public Boolean reject(int musicId, int cid, Musicrejection record,int auditorId) {
        Boolean flag=false;
        Date date = new Date();
        Integer audit = mapper.audit(musicId, cid,date,auditorId);
        record.setRejectiontime(date);
        int i = rejectMapper.insertSelective(record);
        if (audit>=1&&i>=1){
            flag=true;
        }
        return flag;
    }

    @Override
    public List<Object> search(String searchName, String searchNickName,Integer cid) {
        return mapper.search(searchName,searchNickName,cid);
    }

    @Override
    public Integer countSearch(String searchName,String searchNickName,Integer cid) {
        return mapper.countSearch(searchName,searchNickName,cid);
    }

    @Override
    public Music selectByPrimaryKey(Integer musicid) {
        return mapper.selectByPrimaryKey(musicid);
    }

    @Override
    public Map<String, Object> getInfo(int musicId, int cid) {
        if (cid==12){
            return mapper.getRejectionInfo(musicId,cid);
        }else {
            return mapper.getInfo(musicId,cid);
        }

    }


}
